package com.topisv.tms.utils;
import java.io.StringReader;
import java.util.HashMap;
import java.util.Map;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.xml.sax.InputSource;

public class DuXMLDoc {
    public static Map<String,String> getResult(String xmlDoc) {
        //创建一个新的字符串
        StringReader read = new StringReader(xmlDoc);
        //创建新的输入源SAX 解析器将使用 InputSource 对象来确定如何读取 XML 输入
        InputSource source = new InputSource(read);
        //创建一个新的SAXBuilder
        SAXBuilder sb = new SAXBuilder();
        Map<String,String> result = new HashMap<String,String>();
        try {
            //通过输入源构造一个Document
            Document doc = sb.build(source);
            //取的根元素
            Element root = doc.getRootElement();
            Element code = root.getChild("code");
            if(code != null)
            {
            	result.put("code", code.getText());
            }
            Element message = root.getChild("message");
            if(message != null)
            {
            	result.put("message", message.getText());
            }
            
           
        } catch (Exception e) {
        } 
        return result;
    }
   
}